/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package Operations;

import Global.Global;
import java.awt.image.BufferedImage;
import java.util.TreeMap;
import Operations.Bit.*;
import Operations.Algebra.*;
import Operations.Geometry.*;
import Operations.Mor.*;
import Operations.Spatial.*;

/**
 *
 * @author littlechild
 */
public class OperationManager {
    TreeMap<Integer,Operation> map=new TreeMap<Integer,Operation>();
    public OperationManager() {
        init();
    }
    /**
     * This function do not change the original Image input
     * @param opNum
     * @param input
     * @param paras
     * @return
     *      the result of operation.
     *
     */
    public BufferedImage operate(int opNum,BufferedImage input,double paras[]) {
        Operation op=map.get(new Integer(opNum));
        assert input!=null;
        return op.operate(input, paras);
    }

    private void init() {
       map.put(new Integer(Global.opHistogram),new OpHistogram());
       map.put(new Integer(Global.opEqualization), new OpEqualization());
       map.put(new Integer(Global.opContrastStretch),new OpContrastStretch());
       map.put(new Integer(Global.opLinearization), new OpLinearization());
       map.put(new Integer(Global.opThreshold), new OpThreshold());
       map.put(new Integer(Global.opShiftminus),new OpShiftMinus());
       map.put(new Integer(Global.opFlipud), new OpFlipud());
       map.put(new Integer(Global.opFliplr),new OpFliplr());
       map.put(new Integer(Global.opAffine), new OpAffine());
       map.put(new Integer(Global.opPerspective), new OpPerspective());
       Operation neighbour=new OpNeighbour();
       for(int i=Global.opSpatialBegin;i!=Global.opNormSpatialEnd;++i) {
           map.put(new Integer(i),neighbour);
       }
       map.put(new Integer(Global.opCanny), new OpCanny());
       map.put(new Integer(Global.opSusan), new OpSusan());
       Operation mor=new OpMor();
       for (int i=Global.opMorBegin;i!=Global.opMorEnd;++i) {
           map.put(new Integer(i),mor);
       }
    }
    public void register(Integer it, Operation op) {
        map.put(it,op);
    }
}
